﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using SpaceShooter.GameObjects;
using Microsoft.Xna.Framework;
using SpaceShooter.Common;

namespace SpaceShooter
{
    public static class ModelHelper
    {
        public static void DrawGameObject(ICamera camera, DrawableGameObject o, Action<BasicEffect> effectSetter)
        {
            // draw player
            foreach (var mesh in o.Model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.PreferPerPixelLighting = true;

                    effectSetter(effect);

                    effect.World = o.PositionMatrix;
                    effect.View = camera.View;
                    effect.Projection = camera.Projection;
                }

                mesh.Draw();
            }
        }

        public static void DrawGameObject(ICamera camera, Model model, Matrix position, Action<BasicEffect> effectSetter)
        {
            // draw player
            foreach (var mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.PreferPerPixelLighting = true;

                    effectSetter(effect);

                    effect.World = position;
                    effect.View = camera.View;
                    effect.Projection = camera.Projection;
                }

                mesh.Draw();
            }
        }
    }
}
